#ifndef _TR700_DRIVER_H_
#define _TR700_DRIVER_H_
#include <stdint.h>
extern void USART_Configuration();
extern void Init_LED();
#define CTRL_LED_LS  0
#define CTRL_LED_OPM 1
#define LED_ON       1
#define LED_OFF      0
extern void Ctrl_LED(int index, int val);

extern void Init_LaserSwitch();
#define CTRL_CH_OFF   0
#define CTRL_CH1      1
#define CTRL_CH2      2
#define CTRL_CH3      3
#define CTRL_CH_COUNT (unsigned int)(CTRL_CH3 + 1)
extern void Ctrl_LaserSwitch(int index);


void Init_LaserPower(void);


extern void Ctrl_LaserDAC(struct ctrl_param *v);
extern void Ctrl_LaserPower(struct ctrl_param *v);

#define LASER_MODE_OFF   0
#define LASER_MODE_CW    0
#define LASER_MODE_270Hz 1
#define LASER_MODE_1KHZ  2
#define LASER_MODE_2KHZ  3
#define LASER_MODE_COUNT (unsigned int)(LASER_MODE_2KHZ + 1)
extern void Ctrl_LaserMode(int mode);

extern int PeekUartCmd();
int        ReadUart(char *out, int max);

/*ADC*/
extern void ADC_Configuration();

#define AD_CH_OPM (0)
#define AD_CH_LS  (1)
extern uint16_t GetAD(uint8_t chx);


/*OPM*/
extern void Init_OPM_SW();
#define CTRL_OPM_SW_UNUSE (0)
#define CTRL_OPM_SW_LV1   1
#define CTRL_OPM_SW_LV2   2
#define CTRL_OPM_SW_LV3   3
#define CTRL_OPM_SW_LV4   4
#define CTRL_OPM_SW_LV5   5
#define CTRL_OPM_SW_LV6   6
#define CTRL_OPM_SW_LV7   7
extern void Ctrl_OPM_SW(int index);
extern int  Get_OPM_SW();
extern void TIM3_Init();
extern void TIM6_Init();

void FLASH_Configuration();
void Flash_Save();

#define F_ADC2DBM_LOW  (0)
#define F_ADC2DBM_HIGH (1)
float Calc_ADC2dBm(int fun_select, unsigned short adc);
int   Init_Overflow(struct adj_power_flash *p);

#ifdef CONFIG_LOW_PRESENT
#define LOW_PRESENT (CONFIG_LOW_PRESENT)
#else
#define LOW_PRESENT (0.8)  // 80%
#endif

#ifdef CONFIG_OPT_OFFSET
#define OPT_OFFSET (CONFIG_OPT_OFFSET)
#else
#define OPT_OFFSET (5)
#endif
float AutoADC2dBm();
void  AutoCtrl_OPM();

void AutoCtrl_LS();
void SPI_Slave(void);
void SPI_Master(void);
#include "stm32f10x_dma.h"
#include "stm32f10x_spi.h"
extern DMA_InitTypeDef DMA_InitStructure;
extern SPI_InitTypeDef SPI_InitStructure_r;
extern void            EXTI_SPI();
extern void            SPI_OnlyRX();
extern void            SPI_OnlyTX();
void                   SPI_Off();
#endif
